package fun.formoji.commons.util;

/**
 * @author Sukit
 * 性别字段处理工具类
 * 将dmp导出的用户数据中的性别字段值规整化
 */
public class GenderUtils {
    private static final String GENDER_MR = "Mr.";
    private static final String GENDER_DR = "Dr.";
    private static final String GENDER_MRS = "Mrs.";
    private static final String GENDER_MS = "MS.";
    private static final String GENDER_MISS = "Miss.";
    private static final String NULL = "null";
    private static final String NULL_STR = "";

    public static final String MALE = "male";
    public static final String FEMALE = "female";
    public static final String ANY = "any";

    /**
     * 判断该性别是否为男性性别
     * @param gender
     * @return
     */
    private static boolean isMale(String gender) {
        return GENDER_MR.equals(gender) || GENDER_DR.equals(gender) || MALE.equals(gender);
    }

    /**
     * 判断改性别是否为女性性别
     * @param gender
     * @return
     */
    private static boolean isFemale(String gender) {
        return GENDER_MRS.equals(gender) || GENDER_MS.equals(gender) || GENDER_MISS.equals(gender) || FEMALE.equals(gender);
    }

    /**
     * 判断该性别是否为无性别
     * @param gender
     * @return
     */
    private static boolean isAny(String gender) {
        return NULL.equals(gender) || NULL_STR.equals(gender) || gender == null || ANY.equals(gender);
    }

    /**
     * 规整化性别
     * @param rawGender
     * @return
     */
    public static String commonGender(String rawGender) {
        if (rawGender == null || NULL.equals(rawGender) || NULL_STR.equals(rawGender)) {
            return ANY;
        }
        if (isMale(rawGender)) {
            return MALE;
        } else if (isFemale(rawGender)) {
            return FEMALE;
        } else {
            return ANY;
        }
    }

    /**
     * 判断两个性别是否冲突
     * @param userGender
     * @param itemSuitGender
     * @return
     */
    public static boolean conflict(String userGender, String itemSuitGender) {
        if (isMale(userGender)) {
            return isFemale(itemSuitGender);
        } else if (isFemale(userGender)) {
            return isMale(itemSuitGender);
        } else if (isAny(userGender)) {
            return !isAny(itemSuitGender);
        }
        return true;
    }
}
